# @Time    : 2025/1/2 21:39
# @Author  : Zhang Yihao
class Node:
    def __init__(self,elem=-1,lchild=None,rchild=None):
        self.elem=elem
        self.lchild=lchild
        self.rchild=rchild

class Tree:
    def __init__(self):
        self.root=None
        self.help_queue=[]

    def add_tree(self,node:Node):
        self.add_tree(node)
        if self.root is None:
            self.root=node
        else:
            if self.help_queue[0].lchild is None:
                self.help_queue[0].lchild=node
            else:
                self.help_queue[0].rchild=node
                del self.help_queue[0]

    def pre_order(self,node:Node):
        if node is None:
            return
        print(node.elem,end=' ')
        self.pre_order(node.lchild)
        self.pre_order(node.rchild)

    def in_order(self,node:Node):
        if node is None:
            return
        self.in_order(node.lchild)
        print(node.elem,end=' ')
        self.in_order(node.rchild)

    def post_order(self,node:Node):
        if node is None:
            return
        self.post_order(node.lchild)
        self.post_order(node.rchild)
        print(node.elem,end=' ')

    def level_order(self,node:Node):
        if node is None:
            return
        self.help_queue.append(node)
        while self.help_queue:
            node=self.help_queue.pop(0)
            print(node.elem,end=' ')
            if node.lchild:
                self.help_queue.append(node.lchild)
            if node.rchild:
                self.help_queue.append(node.rchild)

class Student:
    def __init__(self,name,grade,age):
        self.name=name
        self.grade=grade
        self.age=age

    def __repr__(self):
        """
        相对于__str__来说，更方便，可以返回非字符串类型
        :return:
        """
        return repr((self.name,self.grade,self.age))

a=[]
a.append(Student('john','A',18))
a.append(Student('peter','B',12))
a.append(Student('alan','C',20))
print(sorted(a,key=lambda x:x.grade))
a.sort(key=lambda x:x.name)
print(a)